export default class LocationTool {
	constructor(viewer) {
		this.viewer = viewer;
		this.status = false;
		this._init();
	}
	_init() {}
	start() {
		// 是否开启了
		this.status = true;
		if (this.viewer.measureTool) {
			this.viewer.measureTool.switchOff();
		}
		let drawableConfig = new Glodon.Bimface.Plugins.Drawable.DrawableContainerConfig();
		drawableConfig.viewer = this.viewer;
		//容器
		this.viewer.drawableContainer = new Glodon.Bimface.Plugins.Drawable.DrawableContainer(
			drawableConfig
		);

		this.viewer.addEventListener(
			Glodon.Bimface.Viewer.Viewer3DEvent.MouseClicked,
			// (data) => this.location(data)
			this.location
		);
	}
	stop() {
		if (this.status) {
			this.viewer.measureTool.exit();
			this.status = false;
			this.viewer.removeEventListener(
				Glodon.Bimface.Viewer.Viewer3DEvent.MouseClicked,
				this.location
			);
		}
	}
	location = (data) => {
		if (!data) return;
		// /引线标签的配置类
		let config = new Glodon.Bimface.Plugins.Drawable.LeadLabelConfig();
		//引线折点的相对位置
		config.offset = { x: 27, y: -47 };
		//引线标签的内容
		config.text = `x:${data.worldPosition.x} \n y:${data.worldPosition.y} \n z:${data.worldPosition.z} `;
		//引线标签关联的构件
		config.objectId = data.componentId;
		//引线标签的世界坐标
		config.worldPosition = data.worldPosition;
		//引线标签是否可拖拽
		config.draggable = false;
		config.width = '170px';
		//引线标签的视图
		config.viewer = this.viewer;

		let label = new Glodon.Bimface.Plugins.Drawable.LeadLabel(config);
		this.viewer.drawableContainer.addItem(label);
	};
}
LocationTool.toolId = 'LocationTool';
